﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SJC.Services
{
    public class UsersTService
    {
        static string tableName = "UsersT";
        //返回表格成功更新的行数
        public static int UpdateSqlDBBuilder()
        {
            return DBHelper.UpdateSqlDBBuilder(tableName);
        }
        //登录-->查询           若查询成功返回1
        public static int countByAccount(string account, string password)
        {
            string sql = "select count(*) from UsersT where account='" + account + "' and pwd='" + password + "' ";
            return DBHelper.Cha_a(sql);
        }
        //显示表格数据方法
        public static DataTable ShowDataTable()
        {
            string sqlCommand = "select * from " + tableName;
            return DBHelper.ShowDataTable(sqlCommand, tableName);
        }
        //查询用户名
        public static string selectAccountById(int userId)
        {
            string account = null;
            string sql = "select account from " + tableName + " where userId='" + userId + "'";
            SqlDataReader r = DBHelper.Cha_b(sql);
            while (r.Read())
            {
                account = r["Account"].ToString();
            }

            r.Close();
            return account;
        }


        //重置密码--->更新Pwd     成功返回受影响行数
        public static int updatePwd(string newPwd, string emailAddress)
        {
            string sql = "UPDATE " + tableName + " SET Pwd='" + newPwd + "' WHERE Email='" + emailAddress + "'";
            return DBHelper.ZSG_a(sql);
        }
        //用户注册-->插入记录        成功返回受影响行数
        public static int addUser(string emailAddress, string account, string pwd)
        {
            string sql = "insert into " + tableName + " (Email,Account,Pwd) values ('" + emailAddress + "','" + account + "','" + pwd + "')";
            return DBHelper.ZSG_a(sql);
        }
        //读卡登录-->查询用户        成功返回非空
        public static int selectByCarNum(string CarNum)
        {
            string sql="select * from "+tableName+ " where CarNum='" + CarNum+"'";
            return DBHelper.Cha_a(sql);
        }
    }
}
